package com.artPreter.service.impl;


import com.artPreter.mapper.SystemConfigMapper;
import com.artPreter.pojo.SystemConfig;
import com.artPreter.pojo.SystemConfig;
import com.artPreter.service.ISystemConfigService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 系统设置表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2024-12-27
 */
@Service
public class SystemConfigServiceImpl extends ServiceImpl<SystemConfigMapper, SystemConfig> implements ISystemConfigService {

    @Override
    public IPage<SystemConfig> getPage(Integer currentPage, Integer size, SystemConfig systemConfig) {
        size = 99;
        IPage<SystemConfig> artTypeIPage = new Page<>(currentPage, size);
        LambdaQueryWrapper<SystemConfig> queryWrapper = new LambdaQueryWrapper<>();
        artTypeIPage = this.baseMapper.selectPage(artTypeIPage, queryWrapper);
        return artTypeIPage;
    }

    @Override
    public void saveBatchData(List<SystemConfig> systemConfigList) {
        for (int i = 0; i < systemConfigList.size(); i++) {
            SystemConfig systemConfig = new SystemConfig();
            systemConfig.setConfigValue(systemConfigList.get(i).getConfigValue());
            systemConfig.setId(systemConfigList.get(i).getId());
            this.baseMapper.updateById(systemConfig);
        }
    }

    @Override
    public List<SystemConfig> getList(SystemConfig systemConfig) {
        LambdaQueryWrapper<SystemConfig> queryWrapper = new LambdaQueryWrapper<>();
        List<SystemConfig> systemConfigs = this.baseMapper.selectList(queryWrapper);
        return systemConfigs;
    }

    @Override
    public void delete(SystemConfig systemConfig) {
        this.baseMapper.deleteById(systemConfig);
    }

    @Override
    public void edit(SystemConfig systemConfig) {
        this.baseMapper.updateById(systemConfig);
    }

    @Override
    public void add(SystemConfig systemConfig) {
        LambdaQueryWrapper<SystemConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SystemConfig::getKeyName,systemConfig.getKeyName());
        List<SystemConfig> systemConfigs = this.baseMapper.selectList(queryWrapper);
        if(systemConfigs.size()>0){

        }else{
            this.baseMapper.insert(systemConfig);
        }
    }
}
